import request from '@/utils/request'
import { getToken } from '@/utils/auth' // 验权
import { JSEncrypt } from 'jsencrypt'//RSA加密

export async function login(username, password, ranval, verifycode) {


  //获取rsa公钥
  const rsakey = await request({ url: '/check/GetRSAPublicKey', method: 'get', }).then(res => { return res.result; });
  //密钥加密
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(rsakey)
  const rsapwd = encryptor.encrypt(password);
  let pdata = { Account: username, Password: rsapwd, AppKey: 'openau1th', ranval: ranval, verifycode: verifycode };

  return request({ url: '/check/login', method: 'post', data: pdata })
}

export function getInfo(token) {
  return request({
    url: '/check/getusername',
    method: 'get',
    params: { token }
  })
}

export function getUserProfile() {
  return request({
    url: '/check/getuserprofile',
    method: 'get',
    params: { token: getToken() }
  })
}

export function getModules() {
  return request({
    url: '/check/getmodules',
    method: 'get',
    params: { token: getToken() }
  })
}

export function getModulesTree() {
  return request({
    url: '/Check/GetModulesTree',
    method: 'get',
    params: { token: getToken() }
  })
}

export function getOrgs() {
  return request({
    url: '/check/getorgs',
    method: 'get',
    params: { token: getToken() }
  })
}

export function getSubOrgs(data) {
  return request({
    url: '/check/getSubOrgs',
    method: 'get',
    params: data
  })
}

export function logout() {
  return request({
    url: '/check/logout',
    method: 'post'
  })
}
